from django.db import models
from django.contrib.auth.models import User


class ImageGeneration(models.Model):
    """AI图像生成记录"""
    STATUS_CHOICES = [
        ('pending', '待处理'),
        ('processing', '生成中'),
        ('completed', '已完成'),
        ('failed', '生成失败'),
    ]
    
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户')
    prompt = models.TextField(verbose_name='提示词', help_text='描述您想要生成的图像')
    negative_prompt = models.TextField(verbose_name='负面提示词', blank=True, help_text='不希望出现的内容')
    style = models.CharField(max_length=50, verbose_name='图像风格', default='realistic')
    width = models.IntegerField(default=512, verbose_name='宽度')
    height = models.IntegerField(default=512, verbose_name='高度')
    status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='pending', verbose_name='状态')
    image_url = models.URLField(blank=True, verbose_name='图像链接')
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_at = models.DateTimeField(auto_now=True, verbose_name='更新时间')
    
    class Meta:
        verbose_name = 'AI图像生成'
        verbose_name_plural = 'AI图像生成'
        ordering = ['-created_at']
    
    def __str__(self):
        return f'{self.user.username} - {self.prompt[:50]}...' if len(self.prompt) > 50 else f'{self.user.username} - {self.prompt}'
